
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"


********************************************************************************
********************************************************************************
**# TABLE C.5

import delimited "${Inputs}\Cook_payday_sumstats.tex", clear

	replace v1 = v1 + "," + v2 if !mi(v2) & mi(v3) & mi(v4)
	replace v1 = v1 + "," + v2 + "," + v3 if !mi(v2) & !mi(v3) & mi(v4)
	replace v1 = v1 + "," + v2 + "," + v3 + "," + v4 if !mi(v2) & !mi(v3) & !mi(v4)
	drop v2 v3 v4 
	rename v1 v 
	drop if v=="\bottomrule \end{tabular} }" | regexm(v, "multicolumn")
	
	replace v = subinstr(v, "\sym{", "", .)
	replace v = subinstr(v, "}", "", .)
	replace v = subinstr(v, "\\", "", .)
	split v, parse("&")
	drop v
	replace v1 = trim(v1) 
	replace v2 = trim(v2)
	replace v3 = trim(v3) 
	
	gen group = "inq" if _n < 10
	replace group = "acc" if _n >= 10
	replace v1 = "" if regexm(v1, "textbf")
	drop if mi(v1) & mi(v2) & mi(v3)
	
	gen type = "co" if !mi(v1)
	replace type = "obs" if regexm(v1, "Number of")
	replace type = "uobs" if regexm(v1, "Number of Unique")
	replace type = "se" if mi(type)
	
	replace v1 = v1[_n-1] if mi(v1)
	gen identifier = lower(substr(v1, 1, 3))
	replace identifier = identifier + "2" if regexm(v1, ">")
	replace identifier = "x" if type=="obs" | type=="uobs"
	
	isid group type identifier
	rename v1 full_name 
	reshape long v, i(full_name group type identifier) j(col) string
	replace col = "c" + col 
	
	isid group type identifier col
	order full_name group identifier type col v 
	sort group identifier type col 
	
	replace v = "(3,388.13)" if v=="(3388.13)"
	replace v = "(2,595.41)" if v=="(2595.41)"
	compress 

levelsof group, local(grps)
levelsof identifier, local(ides)
levelsof type, local(typs)
levelsof col, local(cols)

foreach grx in `grps'{
	local id1 = "`grx'"
	
	foreach idx in `ides' {
		local id2 = "`idx'"
		
		foreach tyx in `typs' {
			local id3 = "`tyx'"
			
			foreach cox in `cols' {
				local id4 = "`cox'"
				
				levelsof v if group=="`grx'" & identifier=="`idx'" & type=="`tyx'" ///
						& col=="`cox'", clean local(`id1'_`id2'_`id3'_`id4')
						
				di "`id1'_`id2'_`id3'_`id4'"
			}
		}
	}
}
	
gl x " "	
	
texdoc init "${Outputs}/Supplementary data_Table_C5.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c} \hline \toprule ///
	& Random Sample & Eviction Court Sample \\

tex	& (1) & (2) \\
tex \cmidrule{2-3}

tex $x \textbf{\underline{Inquiries:}} & & \\
tex $x ~~~Online 	& `inq_onl_co_c2' & `inq_onl_co_c3' \\
tex 			& `inq_onl_se_c2' & `inq_onl_se_c3' \\

tex $x ~~~Storefront 	& `inq_sto_co_c2' & `inq_sto_co_c3' \\
tex 				& `inq_sto_se_c2' & `inq_sto_se_c3' \\

tex $x ~~~Other Type of Inquiry 	& `inq_oth_co_c2' & `inq_oth_co_c3' \\
tex 							& `inq_oth_se_c2' & `inq_oth_se_c3' \\
tex & & \\
tex $x ~~~Number of Inquiries 			& `inq_x_obs_c2' 	& `inq_x_obs_c3' \\
tex $x ~~~Number of Unique Individuals 	& `inq_x_uobs_c2' 	& `inq_x_uobs_c3' \\
 
tex \midrule
tex $x \textbf{\underline{Accounts:}} & & \\
tex $x ~~~Amount 	& `acc_amo_co_c2' & `acc_amo_co_c3' \\
tex 			& `acc_amo_se_c2' & `acc_amo_se_c3' \\

tex $x ~~~Single Payment, Duration $ \leq $ 1 Month 	& `acc_sin_co_c2' & `acc_sin_co_c3' \\
tex  												& `acc_sin_se_c2' & `acc_sin_se_c3' \\ 	

tex $x ~~~Single Payment, Duration $ > $ 1 Month 	& `acc_sin2_co_c2' & `acc_sin2_co_c3' \\
tex  											& `acc_sin2_se_c2' & `acc_sin2_se_c3' \\ 	

tex $x ~~~Installment, Duration $ \leq $ 1 Month 	& `acc_ins_co_c2' & `acc_ins_co_c3' \\
tex 											& `acc_ins_se_c2' & `acc_ins_se_c3' \\

tex $x ~~~Installment, Duration $ > $ 1 Month & `acc_ins2_co_c2' & `acc_ins2_co_c3' \\
tex 										& `acc_ins2_se_c2' & `acc_ins2_se_c3' \\

tex $x ~~~Other Type of Account 	& `acc_oth_co_c2' & `acc_oth_co_c3' \\
tex 							& `acc_oth_se_c2' & `acc_oth_se_c3' \\
tex & & \\
tex $x ~~~Number of Accounts 				& `acc_x_obs_c2' 	& `acc_x_obs_c3' \\
tex $x ~~~Number of Unique Individuals 	& `acc_x_uobs_c2' 	& `acc_x_uobs_c3' \\

tex \bottomrule \\
tex	\end{tabular} }
texdoc close





********************************************************************************
********************************************************************************
**# Table C.6 

use "${Intermediate}\Combined for forloops.dta", clear

keep if inlist(outcome, "paya", "payi", "numa", "numi") & inlist(time, "q0104", "q0508") & inlist(spec, "ldv", "ivac")

********************************************************************************
* DEFINE LOCALS THROUGH FOR LOOPS HERE
********************************************************************************
levelsof outcome, local(outcomes)
levelsof group, local(groups)
levelsof spec, local(specs)
levelsof time, local(times)
levelsof geo, local(geos)
levelsof item, local(items)

foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach grox in `groups' {
		local id2 = "`grox'"
		
		foreach spex in `specs' {
			local id3 = "`spex'"
			
			foreach timx in `times' {
				local id4 = "`timx'"
				
				foreach geox in `geos' {
					local id5 = "`geox'"
					
					foreach itex in `items' {
						local id6 = "`itex'"
		
					levelsof value if 	outcome=="`outx'" & ///
										group=="`grox'" & ///
										spec=="`spex'" & ///
										time=="`timx'" & ///
										geo=="`geox'" & ///
										item=="`itex'" , ///
						clean local(`id1'_`id2'_`id3'_`id4'_`id5'_`id6')
						di "`id1'_`id2'_`id3'_`id4'_`id5'_`id6'"
						
					}
				}
			}
		}
	}
}




texdoc init "${Outputs}/Supplementary data_Table_C6.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c c c} \hline \toprule ///
	& \multicolumn{3}{c}{\textbf{1-4 Quarters After Filing}} ///
	& & \multicolumn{3}{c}{\textbf{5-8 Quarters After Filing}} \\
	
tex \cmidrule{2-4} \cmidrule{6-8}
	
tex	& $ {\scriptsize \mathbb{E}[Y \vert E=0]}$ & OLS & IV ///
	& & $ {\scriptsize \mathbb{E}[Y \vert E=0]}$ & OLS & IV \\

tex & (1) & (2) & (3) & & (4) & (5) & (6) \\
tex \cline{2-4} \cline{6-8}
tex 					 	& & & & & & & \\
							
tex $x \textbf{Any payday inquiry $\times 100$:}  		& `payi_a_ldv_q0104_c_m' 		& `payi_a_ldv_q0104_c_co' 		& `payi_a_ivac_q0104_c_co' ///
							& & `payi_a_ldv_q0508_c_m' 		& `payi_a_ldv_q0508_c_co' 		& `payi_a_ivac_q0508_c_co' \\ 
tex 						& `payi_a_ldv_q0104_c_mse' 		& `payi_a_ldv_q0104_c_se' 		& `payi_a_ivac_q0104_c_se' ///
							& & `payi_a_ldv_q0508_c_mse' 	& `payi_a_ldv_q0508_c_se' 		& `payi_a_ivac_q0508_c_se' \\ 				
tex $x 				 		& \multicolumn{3}{r}{[`payi_a_ldv_q0104_c_obs']} 				& & \multicolumn{3}{r}{[`payi_a_ldv_q0508_c_obs']} \\	

tex $x \textit{By Group} 	& & & & & & & \\								
tex $x ~~~Female 			& `payi_f_ldv_q0104_c_m' 		& `payi_f_ldv_q0104_c_co' 		& `payi_f_ivac_q0104_c_co' ///
							& & `payi_f_ldv_q0508_c_m' 		& `payi_f_ldv_q0508_c_co' 		& `payi_f_ivac_q0508_c_co' \\ 
tex 						& `payi_f_ldv_q0104_c_mse' 		& `payi_f_ldv_q0104_c_se' 		& `payi_f_ivac_q0104_c_se' ///
							& & `payi_f_ldv_q0508_c_mse' 	& `payi_f_ldv_q0508_c_se' 		& `payi_f_ivac_q0508_c_se' \\ 

tex \midrule 
tex 						& & & & & & & \\
tex $x \textbf{Number of payday inquiries:}  		& `numi_a_ldv_q0104_c_m' 		& `numi_a_ldv_q0104_c_co' 		& `numi_a_ivac_q0104_c_co' ///
							& & `numi_a_ldv_q0508_c_m' 		& `numi_a_ldv_q0508_c_co' 		& `numi_a_ivac_q0508_c_co' \\ 
tex 						& `numi_a_ldv_q0104_c_mse' 		& `numi_a_ldv_q0104_c_se' 		& `numi_a_ivac_q0104_c_se' ///
							& & `numi_a_ldv_q0508_c_mse' 	& `numi_a_ldv_q0508_c_se' 		& `numi_a_ivac_q0508_c_se' \\ 		
						
							

tex $x \textit{By Group} 	& & & & & & & \\								
tex $x ~~~Female 			& `numi_f_ldv_q0104_c_m' 		& `numi_f_ldv_q0104_c_co' 		& `numi_f_ivac_q0104_c_co' ///
							& & `numi_f_ldv_q0508_c_m' 		& `numi_f_ldv_q0508_c_co' 		& `numi_f_ivac_q0508_c_co' \\ 
tex 						& `numi_f_ldv_q0104_c_mse' 		& `numi_f_ldv_q0104_c_se' 		& `numi_f_ivac_q0104_c_se' ///
							& & `numi_f_ldv_q0508_c_mse' 	& `numi_f_ldv_q0508_c_se' 		& `numi_f_ivac_q0508_c_se' \\
													
tex \midrule 		
tex 						& & & & & & & \\					
tex $x \textbf{Any payday loan $\times 100$:}  		& `paya_a_ldv_q0104_c_m' 		& `paya_a_ldv_q0104_c_co' 		& `paya_a_ivac_q0104_c_co' ///
							& & `paya_a_ldv_q0508_c_m' 		& `paya_a_ldv_q0508_c_co' 		& `paya_a_ivac_q0508_c_co' \\ 
tex 						& `paya_a_ldv_q0104_c_mse' 		& `paya_a_ldv_q0104_c_se' 		& `paya_a_ivac_q0104_c_se' ///
							& & `paya_a_ldv_q0508_c_mse' 	& `paya_a_ldv_q0508_c_se' 		& `paya_a_ivac_q0508_c_se' \\ 										
tex $x 				 		& \multicolumn{3}{r}{[`paya_a_ldv_q0104_c_obs']} 				& & \multicolumn{3}{r}{[`paya_a_ldv_q0508_c_obs']} \\								

							
tex $x \textit{By Group} 	& & & & & & & \\								
tex $x ~~~Female 			& `paya_f_ldv_q0104_c_m' 		& `paya_f_ldv_q0104_c_co' 		& `paya_f_ivac_q0104_c_co' ///
							& & `paya_f_ldv_q0508_c_m' 		& `paya_f_ldv_q0508_c_co' 		& `paya_f_ivac_q0508_c_co' \\ 
tex 						& `paya_f_ldv_q0104_c_mse' 		& `paya_f_ldv_q0104_c_se' 		& `paya_f_ivac_q0104_c_se' ///
							& & `paya_f_ldv_q0508_c_mse' 	& `paya_f_ldv_q0508_c_se' 		& `paya_f_ivac_q0508_c_se' \\
							
	
tex \midrule 
tex 						& & & & & & & \\
tex $x \textbf{Number of payday loans:}  		& `numa_a_ldv_q0104_c_m' 		& `numa_a_ldv_q0104_c_co' 		& `numa_a_ivac_q0104_c_co' ///
							& & `numa_a_ldv_q0508_c_m' 		& `numa_a_ldv_q0508_c_co' 		& `numa_a_ivac_q0508_c_co' \\ 
tex 						& `numa_a_ldv_q0104_c_mse' 		& `numa_a_ldv_q0104_c_se' 		& `numa_a_ivac_q0104_c_se' ///
							& & `numa_a_ldv_q0508_c_mse' 	& `numa_a_ldv_q0508_c_se' 		& `numa_a_ivac_q0508_c_se' \\ 			

tex $x \textit{By Group} 	& & & & & & & \\								
tex $x ~~~Female 			& `numa_f_ldv_q0104_c_m' 		& `numa_f_ldv_q0104_c_co' 		& `numa_f_ivac_q0104_c_co' ///
							& & `numa_f_ldv_q0508_c_m' 		& `numa_f_ldv_q0508_c_co' 		& `numa_f_ivac_q0508_c_co' \\ 
tex 						& `numa_f_ldv_q0104_c_mse' 		& `numa_f_ldv_q0104_c_se' 		& `numa_f_ivac_q0104_c_se' ///
							& & `numa_f_ldv_q0508_c_mse' 	& `numa_f_ldv_q0508_c_se' 		& `numa_f_ivac_q0508_c_se' \\
							
							
tex \bottomrule \\
tex	\end{tabular} }
texdoc close